<?php
namespace App\Http\Controllers\Resources;

use App\Http\Controllers\Controller;

use Auth;
use Illuminate\Support\Facades\View;
use Session;
use Request;
class DownloadController extends Controller
{
    public function index(){
        $where = [];
        $allurl = '/Resources/Download/index';
        if(Request::get('first_class')){
            $where['first_class'] = Request::get('first_class');
            $allurl .= '?first_class='.$where['first_class'];
        }

        if(Request::get('second_class'))
            $where['second_class'] = Request::get('second_class');
        $p_id = !empty($where['first_class']) ? $where['first_class'] : 1;
        $seclist = Model('DocClass')->getSecList(['p_id'=>$p_id]);
        $list = Model('Resource')->getList($where);
        $var = compact('list','where','seclist','allurl');
        return view('resources.index',$var);
    }

    public function download(){
        $down = new \App\Factories\FileDownloadFactory;
        $id = Request::input('file_id');
        $list = Model('Resource')->getInfo($id);
        $file = $list['real_path'];
        $name = $list['show_name'].'.'.$list['type'];
        $down->download($file,$name,true);
    }
}